package org.classdef.analyzer.info.method;

import java.util.ArrayList;
import java.util.List;

import org.classdef.analyzer.info.ClassDef;
import org.classdef.analyzer.info.attribute.AttributePool;

/**
 * 
 * 方法池
 *
 */
public class MethodPool {
	private List<MethodInfo> infos = new ArrayList<MethodInfo>();
	
	private ClassDef def;
	
	public void add(short accessFlags, short nameIndex, short descriptorIndex, short attributesCount, AttributePool attributePool){
		MethodInfo methodInfo = new MethodInfo(accessFlags, nameIndex, descriptorIndex, attributesCount, attributePool);
		methodInfo.def = def;
		infos.add(methodInfo);
	}
	
	/**
	 * @return infos
	 */
	public List<MethodInfo> getInfos() {
		return infos;
	}

	public ClassDef getDef() {
		return def;
	}

	public void setDef(ClassDef def) {
		this.def = def;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("[");
		for (MethodInfo info : infos) {
			sb.append(info).append(", ");
		}
		if(sb.length() > 1){
			sb.setLength(sb.length() - 1);
		}
		sb.append("]");
		return sb.toString();
	}

}
